import Vue from 'vue'
import Vuex from 'vuex'
const persistPlugin = store => {
	// 读取状态
	let state = uni.getStorageSync('state')
	if (state) {
		store.replaceState(state)
	}
	// 监听状态变化
	store.subscribe((mutation, state) => {
		uni.setStorageSync('state', state)
	})
}
Vue.use(Vuex)

const store = new Vuex.Store({
	plugins: [persistPlugin],
	state: {
		td: false,
		goulist: [],
		xieyi: {},
		peizhi: {},
		yanxi: {},
		tel: ''
	},
	mutations: {
		tt(state) {
			state.td = true;
		},
		tf(state) {
			state.td = false;
		},
		cun(state, item) {
			state.goulist.push(item)
		},
		fugai(state, arr) {
			state.goulist = arr
		},
		cxieyi(state, str) {
			state.xieyi = str
		},
		cpeizhi(state, str) {
			state.peizhi = str
		},
		cyanxi(state, str) {
			state.yanxi = str
		},
		ctel(state, str) {
			state.tel = str
		},
	},
	actions: {
		//相当于异步的操作,不能直接改变state的值，只能通过触发mutations的方法才能改变
	}
})
export default store